import request from '@/utils/request'
import axios from 'axios'
import {
  Message
} from 'element-ui'
export function uploadFile(fileobj) { // 文件上传
  const param = new FormData() // 创建form对象
  param.append('file', fileobj) // 通过append向form对象添加数据
  // 添加请求头
  const config = {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  }
  return new Promise((resolve, reject) => {
    axios.post(process.env.VUE_APP_BASE_API + '/uplaodFile/upload', param, config)
      .then(response => {
        if (response.data.code === 200) {
          resolve(response.data.result)
        } else {
          Message({
            message: response.data.msg || 'Error',
            type: 'error',
            duration: 5 * 1000
          })
        }
      }).catch(error => {
        reject(error)
      })
  })
}

export function uploadFile2(fileobj) { // 作废
  // console.log(fileobj)
  const params = new FormData()
  params.append('file', fileobj)
  return request({
    method: 'post',
    url: '/uplaodFile/upload',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    params
  })
}
